package com.enlorenz.core.base;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 顺序初始化管理者
 * @author lcb
 */
public class ObjectSeqInitializingManager {
	protected Logger logger=LoggerFactory.getLogger(this.getClass());
    private List<IObjectSeqInitializing> list;

	public void setList(List<IObjectSeqInitializing> list) {
		this.list = list;
	}
	
	/**
	 * 开始初始化
	 */
	public void doInit(){
		int index=0;
		for(IObjectSeqInitializing obj:list){
			logger.info("%%%%%%% "+index+".启动器正在启动["+obj.getClass().getName()
					+"]%%%%%%%");
			//初始化
			initSeq(obj,index++);
		}
	}
	
	protected void initSeq(IObjectSeqInitializing obj,int index){
		//初始化	
		try {
			obj.objectSeqInit();
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List<IObjectSeqInitializing> getList() {
		return list;
	}
	
}
